<?php

namespace Admin\Controller;

use Org\Util;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of LbsProjectController
 *
 * @author Myron
 */
class LbsProjectController extends AdminController {

    public function index() {
        $name = I('name');
        $map['name'] = array('like', '%' . (string) $name . '%');
        $list = $this->lists('lbs_project', $map);
        int_to_string($list);
        $this->assign('_list', $list);
        $this->meta_title = '标题';
        $this->display();
    }

    /**
     * 添加
     * @author 曹梦龙 <138888611@qq.com>
     */
    public function add($aid = '', $name = '', $cityname = '') {
        if (IS_POST) {
            $gr_lbs_project = array(
                'aid' => $aid,
                'name' => $name,
                'cityname' => $cityname,
                'status' => 1,
                'createat' => NOW_TIME,
                'delflag' => 0,
            );
            $id = M('lbs_project')->add($gr_lbs_project);
            if (!$id) {
                $this->error('添加失败！');
            } else {
                $this->success('添加成功！', U('index'));
            };
        } else {
            $applist = M('lbs_application')->where('status=1')->select();
            $this->assign('_applist', $applist);
            $this->display();
        }
    }

    /**
     * 状态修改
     * @author 曹梦龙 <138888611@qq.com>
     */
    public function changeStatus($method = null, $id) {
        $id = is_array($id) ? implode(',', $id) : $id;
        if (empty($id)) {
            $this->error('请选择要操作的数据!');
        }
        $map['id'] = array('in', $id);
        switch (strtolower($method)) {
            case 'forbid':
                $this->forbid('lbs_project', $map);
                break;
            case 'resume':
                $this->resume('lbs_project', $map);
                break;
            case 'delete':
                $this->delete('lbs_project', $map);
                break;
            default:
                $this->error('lbs_project');
        }
    }

}
